package com.dapeng.cleardatabackend.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

/**
 * 通用返回类
 *
 * @author dapeng
 * @param <T>
 */
@Data
@ApiModel(description = "通用返回类")
@AllArgsConstructor
public class BaseResponse<T> implements Serializable {

    @ApiModelProperty(value = "错误码")
    private int code;

    @ApiModelProperty(value = "返回数据")
    private T data;

    @ApiModelProperty(value = "错误信息")
    private String message;

    public BaseResponse(int code, T data) {
        this(code, data, "");
    }

    public BaseResponse(ErrorCode errorCode) {
        this(errorCode.getCode(), null, errorCode.getMessage());
    }
}
